//
//  BSSocket.h
//  BSProject
//
//  Created by nsm on 2019/8/1.
//  Copyright © 2019 beisheng. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

#define _bsSocket   [BSSocket sharedInstance]

typedef void(^BSSocketDidConnectSuccess)(void);
typedef void(^BSSocketDidConnectFailure)(NSError *error);
typedef void(^BSSocketDidDisconnect)(NSError *error);
typedef void(^BSSocketDidSendData)(id data);
typedef void(^BSSocketDidReceiveData)(id data);
typedef void(^BSSocketDidReceivePong)(id pong);
typedef void(^BSSocketDidReconnecting)(NSUInteger count);

@interface BSSocket : NSObject
/** 连接成功 */
@property (nonatomic, copy) BSSocketDidConnectSuccess didConnectSuccess;
/** 连接失败 */
@property (nonatomic, copy) BSSocketDidConnectFailure didConnectFailure;
/** 连接关闭 */
@property (nonatomic, copy) BSSocketDidDisconnect didDisconnect;
/** 收到数据 */
@property (nonatomic, copy) BSSocketDidReceiveData didReceiveData;
/** 发送数据 */
@property (nonatomic, copy) BSSocketDidSendData didSendData;
/** 心跳回执 */
@property (nonatomic, copy) BSSocketDidReceivePong didReceivePong;
/** 重连回调 */
@property (nonatomic, copy) BSSocketDidReconnecting didReconnecting;

+ (instancetype)sharedInstance;

- (BOOL)connectHost:(NSString *)host onPort:(uint16_t)port;

// NSString | NSData
- (void)send:(id)data;
- (void)close;

@end

NS_ASSUME_NONNULL_END
